from win32com.client import Dispatch
import time
import random
class Demo:
    def __init__(self):
        # 创建com对象
        self.op = op = Dispatch("op.opsoft.1");
        self.hwnd = 0;
        self.send_hwnd = 0;
        op.SetPath("C:\\Users\\Administrator\\Desktop\\houtai\\image\\");
        #全局资源的位置

    def test_qidong(self):
        # 输出插件版本号
        print("版本号", self.op.Ver());
        a = self.op.WinExec("D:\\BaiduNetdisk_7.4.2.2", 1);
        print("打开",a);

    def test_bkmode(self):
      #绑定
        self.hwnd = self.op.FindWindo("dnplayer.exe","LDPlayerMainFrame","雷电模拟器") ;
        print(self.hwnd);
        time.sleep(0)
        hwnd = self.op.FindWindowEx(self.hwnd, "RenderWindow", "TheRender");
        print("找到子窗体", hwnd);
        # time.sleep(0.1);

        r = self.op.BindWindow(hwnd, "opengl", "windows", "windows", 1);
        # opengl 后台模式 normal 前台模式;
        if r == 0:
            print("绑定失败");
        else:
            print("绑定成功,,,,");
            time.sleep(0);

    def test_windos(self):
        op_ret = self.op.GetWindowRect(self.hwnd)
        print(op_ret);
        self.op.SetClientSize(self.hwnd,864,497);
        print("窗口设置为x=867，y=467")
        self.op.MoveWindow(self.hwnd, 10, 10);
        print("窗口移动成功10，10");
        self.op.SetWindowTransparent(self.hwnd,255); #0是隐藏窗口不占位置，完全透明
        #透明度设置
        print("设置透明度成功");

    def test_end(self):
        op_ret = self.op.UnBindWindow();
        # 退出进程
        return op_ret;

    def test_jietu(self):
        op = self.op.Capture(1, 1, 864, 491, "screen.bmp")
        if op == 1:
            print("方法调用成功");
        else:
            print("截图失败");

    def test_dianji(self):
        ret1 = self.op.MoveTo(29, 46);
        ret2 = self.op.LeftClick();
        if ret1==0&ret2==0:
            print("失败");
        else:
            print("成功！");
if __name__ == '__main__':
    demo = Demo();
    #初始化
    demo.test_qidong()
    #打开雷电的方法
    demo.test_bkmode()
    #绑定窗体
    demo.test_windos()
    #移动窗体
    demo.test_jietu()
    #截图
    time.sleep(1)
    #等待1秒
    demo.test_dianji()
    #测试点击
    demo.test_end()
    #释放函数
    print("成功结束")

